package cn.valo.org.service.impl;

import cn.valo.basic.service.impl.BaseServiceImpl;
import cn.valo.basic.util.MD5Utils;
import cn.valo.basic.util.StrUtils;
import cn.valo.org.domain.Employee;
import cn.valo.org.mapper.EmployeeMapper;
import cn.valo.org.service.IEmployeeService;
import cn.valo.user.domain.Logininfo;
import cn.valo.user.mapper.LogininfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService{
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private LogininfoMapper logininfoMapper;
    @Override
    public void save(Employee employee) {
        //根据用户输入的密码加密
        String salt = StrUtils.getComplexRandomString(32);
        String md5Pwd = MD5Utils.encrypByMd5(employee.getPassword() + salt);
        employee.setSalt(salt);
        employee.setPassword(md5Pwd);
        employeeMapper.insert(employee);
        Logininfo logininfo = new Logininfo();
        logininfo.setUsername(employee.getUsername());
        logininfo.setType(0);
        logininfo.setPassword(employee.getPassword());
        logininfo.setPhone(employee.getPhone());
        logininfo.setEmail(employee.getEmail());
        logininfo.setSalt(employee.getSalt());
        logininfo.setDisable(1);
        logininfoMapper.insert(logininfo);
    }
}
